'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const M = 'flow',
  w = 'block',
  h = 'quoted';
function t(
  s,
  c,
  f = 'flow',
  {
    indentAtStart: F,
    lineWidth: u = 80,
    minContentWidth: D = 20,
    onFold: b,
    onOverflow: v,
  } = {},
) {
  if (!u || u < 0) return s;
  const L = Math.max(1 + D, 1 + u - c.length);
  if (s.length <= L) return s;
  const r = [],
    p = {};
  let a = u - c.length;
  typeof F == 'number' && (F > u - Math.max(2, D) ? r.push(0) : (a = u - F));
  let i,
    n,
    g = !1,
    e = -1,
    d = -1,
    _ = -1;
  f === w && ((e = k(s, e)), e !== -1 && (a = e + L));
  for (let o; (o = s[(e += 1)]); ) {
    if (f === h && o === '\\') {
      switch (((d = e), s[e + 1])) {
        case 'x':
          e += 3;
          break;
        case 'u':
          e += 5;
          break;
        case 'U':
          e += 9;
          break;
        default:
          e += 1;
      }
      _ = e;
    }
    if (
      o ===
      `
`
    )
      f === w && (e = k(s, e)), (a = e + L), (i = void 0);
    else {
      if (
        o === ' ' &&
        n &&
        n !== ' ' &&
        n !==
          `
` &&
        n !== '	'
      ) {
        const l = s[e + 1];
        l &&
          l !== ' ' &&
          l !==
            `
` &&
          l !== '	' &&
          (i = e);
      }
      if (e >= a)
        if (i) r.push(i), (a = i + L), (i = void 0);
        else if (f === h) {
          for (; n === ' ' || n === '	'; ) (n = o), (o = s[(e += 1)]), (g = !0);
          const l = e > _ + 1 ? e - 2 : d - 1;
          if (p[l]) return s;
          r.push(l), (p[l] = !0), (a = l + L), (i = void 0);
        } else g = !0;
    }
    n = o;
  }
  if ((g && v && v(), r.length === 0)) return s;
  b && b();
  let O = s.slice(0, r[0]);
  for (let o = 0; o < r.length; ++o) {
    const l = r[o],
      $ = r[o + 1] || s.length;
    l === 0
      ? (O = `
${c}${s.slice(0, $)}`)
      : (f === h && p[l] && (O += `${s[l]}\\`),
        (O += `
${c}${s.slice(l + 1, $)}`));
  }
  return O;
}
function k(s, c) {
  let f = s[c + 1];
  for (; f === ' ' || f === '	'; ) {
    do f = s[(c += 1)];
    while (
      f &&
      f !==
        `
`
    );
    f = s[c + 1];
  }
  return c;
}
exports.FOLD_BLOCK = w;
exports.FOLD_FLOW = M;
exports.FOLD_QUOTED = h;
exports.foldFlowLines = t;
